﻿/*
 * @file: OrdersBLL.cs
 * @in namespace: BLL
 */
using System;
using DAL;

/// <summary>
/// Summary description for OrdersBLL
/// </summary>
namespace BLL
{
    public class OrdersBLL
    {
        public OrdersBLL()
        {
            //
            // TODO: Add constructor logic here
            //
        }



        #region IOrders Members

        /// <summary>
        /// GetOrders
        /// </summary>
        /// <returns>Records corresponding</returns>
        public static Orders[] GetOrders(bool allowFilter)
        {
            try
            {
                return DataAccessHelper.GetOrdersDA().GetOrders(allowFilter);
            }
            catch (Exception ex)
            {
                throw ex; 
            }
        }

        /// <summary>
        /// GetOrdersByUser
        /// </summary>
        /// <param name="userID">User ID</param>
        /// <returns>Records corresponding</returns>
        public static Orders[] GetOrdersByUser(int userID, bool allowFilter)
        {
            try
            {
                return DataAccessHelper.GetOrdersDA().GetOrdersByUser(userID, allowFilter);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }


        /// <summary>
        /// GetOrdersByDate
        /// </summary>
        /// <param name="ordersDate">Orders Date</param>
        /// <returns>Records corresponding</returns>
        public static Orders[] GetOrdersByDate(string ordersDate, bool allowFilter)
        {
            try
            {
                return DataAccessHelper.GetOrdersDA().GetOrdersByDate(ordersDate, allowFilter);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }

        /// <summary>
        /// GetOrderByOrderID
        /// </summary>
        /// <param name="orderID">Order ID</param>
        /// <returns>Record corresponding</returns>
        public static Orders GetOrderByOrderID(int orderID, bool allowFilter)
        {
            try
            {
                return DataAccessHelper.GetOrdersDA().GetOrderByOrderID(orderID, allowFilter);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }

        /// <summary>
        /// InsertOrder
        /// </summary>
        /// <param name="orders">Orders entity</param>
        /// <param name="autoNumber">Current Order ID inserted(output)</param>
        /// <returns>1 if successful, 0 if error occurred</returns>
        public static int InsertOrder(Orders orders, out int autoNumber)
        {
            try
            {
                if (orders.UserID == 0)
                    throw new OnlineFloralDeliveryException(2, "UserID is not allow null or empty");
                else if (orders.TotalAmount == 0)
                    throw new OnlineFloralDeliveryException(2, "TotalAmount is not allow null or empty");

                return DataAccessHelper.GetOrdersDA().InsertOrder(orders, out autoNumber);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }

        public static int DisableOrder(int orderID, bool isEnable) {
            try
            {
                return DataAccessHelper.GetOrdersDA().DisableOrder(orderID, isEnable);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }

        #endregion
    }
}